//
//  ChapterCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/12.
//

import UIKit

class ChapterCell: UITableViewCell {
    
    lazy var chapterLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 16)
        return label
    }()
    
    lazy var lockImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "read_character_lock"))
        image.isHidden = true
        return image
    }()

    var durChapterId = 0
    
    var model: ChapterDetailModel? {
        didSet {
            if let m = model {
                chapterLabel.text = "\(tag) \(m.chapterName)"
                lockImage.isHidden = m.status == 1
                chapterLabel.textColor = .init(named: m.chapterId.intValue == durChapterId ? "red_FE95B4" : "black_333333")
            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .white
        contentView.addSubview(chapterLabel)
        contentView.addSubview(lockImage)
        chapterLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(15)
            make.right.equalTo(-48)
        }
        lockImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12)
            make.width.height.equalTo(24)
        }
    }
    
    func darkModeConfig() {
        backgroundColor = isDark() ? .init(named: "black_222222") : .white
        chapterLabel.textColor = model?.chapterId.intValue == durChapterId ? .init(named: "red_FE95B4") : .init(named: isDark() ? "gray_666666" : "black_333333")
    }

        
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
